import React, { useRef } from "react";

import { Form, Input, Button } from "@arco-design/web-react";
// import { RequestHandle, uploadFile } from "@/api/resman";

const ButtonStyle = {
	width: "38px",
	height: "28px",
	padding: 0,
	background: "#2c374b",
	border: "none",
	borderLeft: "1px solid #3a4a66",
	borderTopRightRadius: "5px",
	borderBottomRadius: "5px",
	fontSize: "12px"
};

const FileIndex = props => {
	// const { cItem } = props;
	// console.log(item);

	const uploadRef = useRef(0);

	// 上传图标点击事件
	const onUploadFile = async fileData => {
		// const uploadRet = await uploadFile(fileData);
		// const { code, data } = uploadRet;
		// if (code === 0) {
		// 	props.onChange(data);
		// }
	};

	function dynamicUpload(sid) {
		const input = document.createElement("input");
		input.type = "file";
		input.accept = uploadRef.current ? ".jpg" : "*.*";
		input.click();
		input.onchange = function () {
			// const file = input.files[0];
			const files = input.files;
			const filesData = files && files.length === 1 ? files[0] : files;
			const params = new FormData();

			params.append("file", filesData); // 第一个参数是后台读取的请求key值
			onUploadFile(params, sid);
		};
	}

	return (
		<>
			<Input
				{...props}
				// readOnly
				style={{ width: 155 }}
				addonafter={
					<Button type="primary" onClick={dynamicUpload} style={ButtonStyle}>
						上传
					</Button>
				}
			/>
		</>
	);
};

export default FileIndex;
